<?php
	session_start();
	require('classUsuarios.php');
	require('../includes/conn.php');

	$arrayUsuarios = array();
	
	$sql = 'select a.*,b.nome as nomeSuperior from usuarios a 
			inner join usuarios b 
			on (a.idSuperior = b.id)
			where a.status = 1';
			
	$rs = $db->query($sql);
	
	foreach ($rs as $reg)
	{
		$user = new usuarios();  	
		$user->id = $reg['id'];
		$user->nome = $reg['nome'];
		$user->cpf = $reg['cpf'];		
		$user->senha = $reg['senha'];
		$user->setor = $reg['setor'];
		$user->cargo = $reg['cargo'];
		$user->status = $reg['status'];
		$user->ultimoAcesso = $reg['ultimoAcesso'];		
		$user->dataCadastro =  $reg['dataCadastro'];
		$user->telefone = $reg['telefone'];
		$user->email = $reg['email'];
		$user->idSuperior = $reg['IdSuperior'];	
		$user->nomeSuperior = $reg['nomeSuperior'];							
		
		$arrayUsuarios[] = $user;
   }   
?>
<html>
<head>

</head>
<body>

	<script type="text/javascript" src="../frameworks/jquery/1.10.4/js/jquery.js"></script>
	<script type="text/javascript" src="../frameworks/jquery/1.10.4/js/jquery-ui.min.js"></script>
	<script type="text/javascript" src="acoes.js"></script>	
	
	<form action="controlerUser.php" method="post" id="teste">
		
		<label for="acao">Cadastrar</label>
		<input type="radio" name="acao" value="cadastrar" />
		<label for="acao">Editar</label>
		<input type="radio" name="acao" value="editar" />
		<input type="button" id="limpar" onclick="this.form.reset();"/>
		<table>
			<tr>
				<td>
					<label for="id">Codigo Usuario</label>
					<input type="text" name="id" value="" id="idUser" readonly="readonly"/>					
				</td>
				
			</tr>
			<tr>
				<td>
					<label for="nome">Nome</label>
					<input type="text" name="nome" id="nomeUser" />
				</td>
				<td>
					<label for="cpf">Cpf</label>
					<input type="text" name="cpf" id="cpfUser"/>
				</td>			
				<td>
					<label for="telefone">Telefone</label>
					<input type="text" name="telefone" id="telefoneUser" />
				</td>
				<td>
					<label for="email">E-Mail</label>
					<input type="text" name="email" id="emailUser"/>
				</td>		
			</tr>
			<tr>
				<td>
					<label for="setor">Setor</label>
					<input type="text" name="setor" id="setorUser"/>
				</td>
				<td>
					<label for="cargo">Cargo</label>
					<input type="text" name="cargo" id="cargoUser"/>
				</td>
				<td>
					<label for="status">Status</label>
					<select name="status" id="statusUser">
						<option value="1">Ativo</option>
						<option value="0">Afastado</option>
						<option value="0">Demitido</option>
						<option value="0">Ferias</option>						
					</select>										
				</td>
				<td>
					<label for="status">Supervisor</label>
					<select name="idSupervisor" id="idSupervisor">						
						<?			
						foreach ($arrayUsuarios as $reg)
						{
						?>		
							<option value="<?= $reg->id; ?>"><?= $reg->nome; ?></option>
						<?
					   	}   
						?>									
					</select>										
				</td>
			</tr>
			<tr>
				<td>
					<label for="dataCadastro">Data Cadastro</label>
					<input type="text" name="dataCadastro" id="dataCadastroUser"  readonly="readonly"/>
				</td>
				<td>
					<label for="ultimoAcesso">Ultimo Acesso</label>
					<input type="text" name="ultimoAcesso" id="ultimoAcessoUser" readonly="readonly"/>
				</td>				
			</tr>
			<tr>
				<td>
					<input type="submit" name="Cad" value="Cadastrar" />
				</td>
			</tr>
		</table>						
	</form>
	<table>
		<tr>
			<td>Id</td>
			<td>Nome</td>
			<td>Cpf</td>
			<td>Senha</td>
			<td>Setor</td>
			<td>Cargo</td>
			<td>Status</td>
			<td>Ultimo Acesso</td>			
			<td>Data Cadastro</td>
			<td>Telefone</td>
			<td>E-mail</td>
			<td>Id Superior</td>
			<td>Nome Superior</td>
		</tr>
		
		<?			
			foreach ($arrayUsuarios as $reg)
			{
		?>		
				<tr class="clickAqui">					
					<td name='id'>
						<?= $reg->id; ?>	
					</td>
					<td name="nome">		
						<?= $reg->nome; ?>	
					</td>	
					<td name="cpf">		
						<?= $reg->cpf; ?>	
					</td>					
					<td name="senha">		
						<?= $reg->senha; ?>	
					</td>
					<td name="setor">		
						<?= $reg->setor; ?>	
					</td>
					<td name="cargo">		
						<?= $reg->cargo; ?>	
					</td>
					<td name="status">		
						<?= $reg->status; ?>	
					</td>
					<td name="ultimoAcesso">		
						<?= $reg->ultimoAcesso; ?>	
					</td>					
					<td name="dataCadastro">		
						<?= $reg->dataCadastro; ?>	
					</td>
					<td name="telefone">		
						<?= $reg->telefone; ?>	
					</td>
					<td name="email">		
						<?= $reg->email; ?>	
					</td>
					<td name="idSupervisor">		
						<?= $reg->idSuperior; ?>	
					</td>
					<td name="idSupervisor">		
						<?= $reg->nomeSuperior; ?>	
					</td>
				</tr>	
		<?
		   }   
		?>
	</table>
</body>
</html>

